package com.bdth.bdthiss.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.bdth.bdthiss.entity.Contract;
import com.bdth.bdthiss.entity.Customer;
import com.bdth.bdthiss.entity.Userop;
import com.bdth.bdthiss.mapper.UseropMapper;
import com.bdth.bdthiss.service.UseropService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.bdth.bdthiss.vo.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户操作表 服务实现类
 * </p>
 *
 * @author LGP
 * @since 2019-08-27
 */
@Service
public class UseropServiceImpl extends ServiceImpl<UseropMapper, Userop> implements UseropService {

    @Autowired
    private UseropMapper useropMapper;

    @Override
    public Page<Userop> listPages(Pagination pagination, Map<String, Object> query) {
        EntityWrapper<Userop> entityWrapper = new EntityWrapper<>();
        String start = (String)query.get("start");
        if(start!=null && !start.trim().equals(""))
            entityWrapper.ge("name",start);
        String stop = (String)query.get("stop");
        if(stop!=null && !stop.trim().equals(""))
            entityWrapper.le("stop",stop);
        if(pagination.getOrder()!=null) {
            if (pagination.getOrder().toLowerCase().equals("asc")){
                entityWrapper.orderBy(pagination.getSort(), true);
            }else{
                entityWrapper.orderBy(pagination.getSort(), false);
            }
        }
        Page<Userop> page = new Page<>(pagination.getPage()==null?1:pagination.getPage(),
                pagination.getRows()==null?20:pagination.getRows());

        List<Userop> items = useropMapper.selectPage(page,entityWrapper);
        page.setRecords(items);
        return page;
    }

    @Override
    public boolean save(Userop bean) {
        Integer result = useropMapper.insert(bean);
        if (result > 0)
            return true;
        return false;
    }
}
